package leetcode.problems;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by gmwang on 2018/7/25
 * 有效字谜
 */
public class _0902ValidAnagram {
    /**
     * Given two strings s and t , write a function to determine if t is an anagram of s.
     *
     * Example 1:
     *
     * Input: s = "anagram", t = "nagaram"
     * Output: true
     * Example 2:
     *
     * Input: s = "rat", t = "car"
     * Output: false
     * Note:
     * You may assume the string contains only lowercase alphabets.
     * /**
     * 找到多余的
     * @param s,t
     * @return
     */
    public boolean isAnagram(String s, String t) {
        List list = new ArrayList<>();
        List list2 = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            list.add(s.charAt(i));
        }
        for (int i = 0; i < t.length(); i++) {
            list.add(t.charAt(i));
        }
        Collections.sort(list);
        Collections.sort(list2);
        return list.equals(list2);
    }

    @Test
    public void test() {
//        String k = "anagram";
//        String n = "nagaram";
        String k = "art";
        String n = "car";
        boolean res = isAnagram(k, n);
        System.out.println(res);
    }

}
